// pages/industry/industry.js
const app = getApp();
const md5 = require('../../utils/md5.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role: null,
    plat_height: null,
    plat_swi: true,
    plat_text: "更多平台",

    platfrom: null,
    platfrom_name: null,

  },
  getTab() {
    wx.request({
      url: app.globalData.url + 'api/timing/applet/show',
      method: 'POST',
      success: (e) => {
        // console.log(e)
        let is_show = e.data.data.is_show,
          tel = wx.getStorageSync('reg_telephone');
        // if (tel == '18258151021') {
        if (is_show == app.globalData.tab_is_show) {
          this.setData({
            tabbar: {
              color: "#fff",
              selectedColor: "#d0a76c",
              backgroundColor: "#1b1b1b",
              borderStyle: "black",
              list: [{
                  pagePath: "../../pages/industry/industry",
                  text: "行业",
                  iconPath: "../../images/icon/icon_ind.png",
                  selectedIconPath: "../../images/icon/icon_indS.png",
                  selected: true
                },
                {
                  pagePath: "../../pages/mine/mine",
                  text: "我的",
                  iconPath: "../../images/icon/icon_mine.png",
                  selectedIconPath: "../../images/icon/icon_mineS.png",
                  selected: false
                }
              ],
              position: "bottom"
            },
          })
          this.editTabBar();
        } else {
          if (this.data.role == 2) {
            this.setData({
              tabbar: {
                color: "#fff",
                selectedColor: "#d0a76c",
                backgroundColor: "#1b1b1b",
                borderStyle: "black",
                list: [{
                  pagePath: "../../pages/recruit/index/index",
                  text: "招聘",
                  iconPath: "../../images/icon/icon_rec.png",
                  selectedIconPath: "../../images/icon/icon_recS.png",
                  selected: false
                },
                {
                  pagePath: "../../pages/earns/earns",
                  text: "赚钱",
                  iconPath: "../../images/icon/icon_money.png",
                  selectedIconPath: "../../images/icon/icon_moneyS.png",
                  selected: false
                },
                {
                  pagePath: "../../pages/industry/industry",
                  text: "行业",
                  iconPath: "../../images/icon/icon_ind.png",
                  selectedIconPath: "../../images/icon/icon_indS.png",
                  selected: true
                },
                {
                  pagePath: "../../pages/mine/mine",
                  text: "我的",
                  iconPath: "../../images/icon/icon_mine.png",
                  selectedIconPath: "../../images/icon/icon_mineS.png",
                  selected: false
                }
                ],
                position: "bottom"
              },
            })
          }else{
            this.setData({
              tabbar: {
                color: "#fff",
                selectedColor: "#d0a76c",
                backgroundColor: "#1b1b1b",
                borderStyle: "black",
                list: [{
                  pagePath: "../../pages/recruit/index/index",
                  text: "招聘",
                  iconPath: "../../images/icon/icon_rec.png",
                  selectedIconPath: "../../images/icon/icon_recS.png",
                  selected: false
                },
                {
                  pagePath: "../../pages/industry/industry",
                  text: "行业",
                  iconPath: "../../images/icon/icon_ind.png",
                  selectedIconPath: "../../images/icon/icon_indS.png",
                  selected: true
                },
                {
                  pagePath: "../../pages/mine/mine",
                  text: "我的",
                  iconPath: "../../images/icon/icon_mine.png",
                  selectedIconPath: "../../images/icon/icon_mineS.png",
                  selected: false
                }
                ],
                position: "bottom"
              },
            })
          }
          this.editTabBar();
        }
      },
    })
  },
  //切换tabbar的方法  
  editTabBar: function(e) {
    console.log(e)
    var tabbar = this.data.tabbar,
      currentPages = getCurrentPages(),
      _this = currentPages[currentPages.length - 1],
      pagePath = _this.__route__;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (var i in tabbar.list) {
      // tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
    console.log(tabbar)
  },
  click_more: function(e) {
    if (this.data.plat_swi) {
      this.setData({
        plat_height: 1200,
        plat_swi: false,
        plat_text: "收起"

      })
    } else {
      this.setData({
        plat_height: null,
        plat_swi: true,
        plat_text: "更多平台"
      })
    }
  },
  click_detail: function(e) {
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    var plat_id = e.currentTarget.dataset.plat_id;
    var plat_img = e.currentTarget.dataset.plat_img;
    var plat_text = e.currentTarget.dataset.plat_text;
    // console.log('id+' + plat_id);
    // console.log('plat_token+' + plat_token);
    // console.log(e)
    wx.navigateTo({
      url: '../ind_detail/ind_detail?plat_id=' + plat_id + '&&plat_token=' + plat_token + '&&plat_img=' + plat_img + '&&plat_text=' + plat_text
    })

  },
  query: function(ele) {
    var query = wx.createSelectorQuery()
    query.select('.' + ele + '').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function(res) {
      res[0].height // #the-id节点的上边界坐标
      console.log(res[0].height)

    })
  },
  getPlat: function() {
    var that = this;
    var plat_token = '1' + app.globalData.sjcNow + md5.hex_md5(app.globalData.sjcNow) + 'zbzj';
    wx.request({
      method: 'POST',
      url: 'https://xcz.zhibohome.net/api/home/index',
      data: {
        token: plat_token
      },
      success: function(e) {
        // console.log(e)
        var platfrom = e.data.data.platfrom
        that.setData({
          platfrom: platfrom,
          platfrom_name: e.data.data.platfrom
        })
        // console.log(platfrom)
        console.log(e.data.data.platfrom)
      }
    })
  },
  go_user: function() {
    wx.navigateTo({
      url: '../ind_user/ind_user?module=user&&title=土豪用户榜',
    })
  },
  go_gift: function() {
    wx.navigateTo({
      url: '../ind_user/ind_user?module=gift&&title=礼物收入榜',
    })
  },
  go_mes: function() {
    wx.navigateTo({
      url: '../ind_user/ind_user?module=mes&&title=弹幕榜',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var role = wx.getStorageSync('reg_register_role');
    this.setData({
      role: role,
    })
    this.query('con_main');
    // console.log(options)
    this.getTab();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getPlat()
    //授权检测
    if (!(wx.getStorageSync('token'))) {
      wx.redirectTo({
        url: '../author/author',
      })
      // console.log('跳转')
    } else {
      if (wx.getStorageSync('reg_register_role') == '0') {
        wx.redirectTo({
          url: '../selectIdentity/selectIdentity',
        })
        // wx.showModal({
        //   content: '选择角色后才能看详情哦~',
        //   showCancel: false,
        //   cancelColor: '#333',
        //   confirmText: '好的',
        //   confirmColor: '#d0a76c',
        //   success: function(e) {
        //     if (e.confirm) {
        //       wx.navigateTo({
        //         url: '../selectIdentity/selectIdentity',
        //       })
        //     }
        //   },
        // })
      } else {}
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})